/*     */ package com.zimbra.cs.datasource;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.DataSource;
/*     */ import com.zimbra.cs.db.DbDataSource.DataSourceItem;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.Message;
/*     */ import com.zimbra.cs.mailbox.Metadata;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class DataSourceMapping
/*     */ {
/*     */   protected DataSource ds;
/*     */   protected DbDataSource.DataSourceItem dsi;
/*     */   
/*     */   public DataSourceMapping(DataSource ds, DbDataSource.DataSourceItem dsi)
/*     */     throws ServiceException
/*     */   {
/*  31 */     this.ds = ds;
/*  32 */     this.dsi = dsi;
/*  33 */     parseMetaData();
/*     */   }
/*     */   
/*     */   public DataSourceMapping(DataSource ds, int itemId) throws ServiceException {
/*  37 */     this.ds = ds;
/*  38 */     this.dsi = DataSourceDbMapping.getInstance().getMapping(ds, itemId);
/*  39 */     if (this.dsi.remoteId == null)
/*  40 */       throw MailServiceException.NO_SUCH_ITEM(itemId);
/*  41 */     parseMetaData();
/*     */   }
/*     */   
/*     */   public DataSourceMapping(DataSource ds, String remoteId) throws ServiceException {
/*  45 */     this.ds = ds;
/*  46 */     this.dsi = DataSourceDbMapping.getInstance().getReverseMapping(ds, remoteId);
/*  47 */     if (this.dsi.itemId == 0)
/*  48 */       throw MailServiceException.NO_SUCH_ITEM(remoteId);
/*  49 */     parseMetaData();
/*     */   }
/*     */   
/*     */   public DataSourceMapping(DataSource ds, int folderId, int itemId, String remoteId) throws ServiceException
/*     */   {
/*  54 */     this.ds = ds;
/*  55 */     this.dsi = new DbDataSource.DataSourceItem(folderId, itemId, remoteId, new Metadata());
/*     */   }
/*     */   
/*     */   public DataSourceMapping(DataSource ds, int folderId, int itemId, String remoteId, int localFlags) throws ServiceException
/*     */   {
/*  60 */     this.ds = ds;
/*  61 */     this.dsi = new DbDataSource.DataSourceItem(folderId, itemId, remoteId, new Metadata(), localFlags);
/*     */   }
/*     */   
/*     */ 
/*  65 */   public DataSource getDataSource() { return this.ds; }
/*     */   
/*  67 */   public DbDataSource.DataSourceItem getDataSourceItem() { return this.dsi; }
/*     */   
/*  69 */   public int getFolderId() { return this.dsi.folderId; }
/*     */   
/*  71 */   public int getItemId() { return this.dsi.itemId; }
/*     */   
/*     */   public int getItemFlags() throws ServiceException {
/*  74 */     if (this.dsi.itemFlags == -1) {
/*  75 */       Message localMsg = DataSourceManager.getInstance().getMailbox(this.ds).getMessageById(null, this.dsi.itemId);
/*     */       
/*  77 */       this.dsi.itemFlags = localMsg.getFlagBitmask();
/*     */     }
/*  79 */     return this.dsi.itemFlags;
/*     */   }
/*     */   
/*  82 */   public String getRemoteId() { return this.dsi.remoteId; }
/*     */   
/*  84 */   public void setFolderId(int folderId) { this.dsi.folderId = folderId; }
/*     */   
/*  86 */   public void setItemId(int itemId) { this.dsi.itemId = itemId; }
/*     */   
/*  88 */   public void setItemFlags(int itemFlags) { this.dsi.itemFlags = itemFlags; }
/*     */   
/*  90 */   public void setRemoteId(String remoteId) { this.dsi.remoteId = remoteId; }
/*     */   
/*     */   public void add() throws ServiceException {
/*  93 */     DataSourceDbMapping.getInstance().addMapping(this.ds, this.dsi);
/*     */   }
/*     */   
/*     */   public void delete() throws ServiceException {
/*  97 */     DataSourceDbMapping.getInstance().deleteMapping(this.ds, this.dsi.itemId);
/*     */   }
/*     */   
/*     */   public void set() throws ServiceException {
/*     */     try {
/* 102 */       DataSourceDbMapping.getInstance().addMapping(this.ds, this.dsi);
/*     */     } catch (Exception e) {
/* 104 */       delete();
/* 105 */       DataSourceDbMapping.getInstance().addMapping(this.ds, this.dsi);
/*     */     }
/*     */   }
/*     */   
/*     */   public void update() throws ServiceException {
/* 110 */     DataSourceDbMapping.getInstance().updateMapping(this.ds, this.dsi);
/*     */   }
/*     */   
/*     */   protected void parseMetaData()
/*     */     throws ServiceException
/*     */   {}
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/datasource/DataSourceMapping.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */